// pages/me/me.js
const App = getApp();
Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		userInfo:{},
		hasUserInfo:false,
		agreement:false,
		balance:0,
	},
	linkrecruit(){
		wx.navigateTo({
			url: '../recruit/recruit',
		});
	},
	handlereportedit(){
		this.setData({
			agreement: true
		});
	},
	linkrjianli(){
		wx.navigateTo({
			url: '../jianli/jianli',
		});
	},
	agreementConfirm(){
		wx.navigateTo({
			url: '../reportedit/reportedit',
		});
	},
	handleDial(){
		wx.navigateTo({
			url: '../dial/dial',
		});
	},
	agreementClose(){
		this.setData({
			agreement: false
		});
	},
	GetMoney(){
		wx.request({
			url: 'https://www.grabinter.com/User/index',
			method: 'POST',
			header: {
				"Content-Type": 'application/x-www-form-urlencoded'
			},
			data:{
				token:wx.getStorageSync('token')
			},
			success: json => {
				const {data} = json.data;
				this.setData({
					balance:data.balance
				});
			}
		});
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
	},
	watchUserInfo(val){
		const nickname = wx.getStorageSync('nickname');
		const avatar = wx.getStorageSync('avatar');
		this.setData({
			hasUserInfo:App.globalData.hasUserInfo,
			userInfo:{nickname,avatar}
		});
	},
	onLoginEvent: function(event){
		 
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
			
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {
		if(App.globalData.hasUserInfo){
			const nickname = wx.getStorageSync('nickname');
			const avatar = wx.getStorageSync('avatar');
			this.setData({
				hasUserInfo:App.globalData.hasUserInfo,
				userInfo:{nickname,avatar}
			});
			this.GetMoney();
		}else{
			App.handleLoginParam('me');
			App.watch(this.watchUserInfo)
		}
		
		
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
